package com.zhisheng.day10_tlias.controller;
/*
    专门用于处理用户登陆的controller
 */

import com.zhisheng.day10_tlias.entry.Emp;
import com.zhisheng.day10_tlias.entry.R;
import com.zhisheng.day10_tlias.service.EmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("login")
public class LoginController {

    @Autowired
    private EmpService empService;



    @PostMapping
    public R<String> login(@RequestBody Emp emp){
        // 参  调  响
        String  token = empService.selectEmpByUsernameAndPassword(emp);
        // 如果令牌有效,则认为登陆成功,如果令牌无效,则认为登陆失败,登陆失败,xxxx
        if(token.startsWith("登陆失败")){
            return R.fail(token);
        }
        return R.success(token);

    }

}
